using System.Text.Json.Serialization;

namespace CoreManager.MessageQueue.Models;

/// <summary>
/// Kafka消息基类
/// </summary>
public class KafkaMessage
{
    /// <summary>
    /// 消息ID
    /// </summary>
    public string MessageId { get; set; } = Guid.NewGuid().ToString();
    
    /// <summary>
    /// 消息类型
    /// </summary>
    public string MessageType { get; set; } = string.Empty;
    
    /// <summary>
    /// 消息时间戳
    /// </summary>
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
    
    /// <summary>
    /// 消息内容
    /// </summary>
    public object? Data { get; set; }
    
    /// <summary>
    /// 消息来源
    /// </summary>
    public string Source { get; set; } = "CoreManager";
    
    /// <summary>
    /// 消息版本
    /// </summary>
    public string Version { get; set; } = "1.0";
}

/// <summary>
/// 泛型Kafka消息
/// </summary>
/// <typeparam name="T">消息数据类型</typeparam>
public class KafkaMessage<T> : KafkaMessage
{
    /// <summary>
    /// 类型化的消息数据
    /// </summary>
    [JsonIgnore]
    public new T? Data
    {
        get => (T?)base.Data;
        set => base.Data = value;
    }
}

/// <summary>
/// 消息发送结果
/// </summary>
public class MessageSendResult
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool IsSuccess { get; set; }
    
    /// <summary>
    /// 主题名称
    /// </summary>
    public string Topic { get; set; } = string.Empty;
    
    /// <summary>
    /// 分区
    /// </summary>
    public int Partition { get; set; }
    
    /// <summary>
    /// 偏移量
    /// </summary>
    public long Offset { get; set; }
    
    /// <summary>
    /// 错误信息
    /// </summary>
    public string? ErrorMessage { get; set; }
    
    /// <summary>
    /// 消息ID
    /// </summary>
    public string MessageId { get; set; } = string.Empty;
}
